// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vant from 'vant';
import 'vant/lib/index.css';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.config.productionTip = false


Vue.use(Vant);
Vue.use(ElementUI);

router.beforeEach((to, from, next) => {
    //先定义白名单
    let list = ['/login', '/index', '/admin']
    //判断是否在白名单中，如果在进入下个页面
    if (list.indexOf(to.path) >= 0) {
        next()
    } else {
        let mlist = []
        // 取出资源列表
        let menu = JSON.parse(localStorage.getItem('resourcelist'))

        //遍历menu，将url取出来放入新的list中
        for (var i = 0; i < menu.length; i++) {
            mlist.push(menu[i]['url'])
        }
        //是否在服务端配制的url中
        if (mlist.indexOf(to.path) >= 0) {
            next()
        } else {
            alert('您无权访问')
            return;
        }

    }
})


/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    components: { App },
    template: '<App/>'
})
